﻿using System;
using USClientKernel.Template;
using Common.Utils.Helper;
using Game.Logic.Events;

namespace Game.Logic.Manager
{
    public enum GameLangue
    {
        Invalid = 0,
        ZH_CN,              // 中文
        EN_US,              // 英语
    }


    public class GameLangueManager : Singleton<GameLangueManager>
    {
        public GameLangue Langue { private set; get; }
        public GameEvent GameEvent { private set; get; }
        public CSharpLuaTable Config { private set; get; }

        protected override void Init()
        {
            Langue = GameLangue.ZH_CN;
            InitTextConfig();
        }

        private void InitTextConfig()
        {
            Config = GameConfigManager.Instance.LoadConfig(GameDefine.GAME_CONFIG_TEXT);
        }

        public void SetLangue(GameLangue _langue)
        {
            Langue = _langue;
            GameEventManager.Instance.DispatchEvent(GameEvent.Create(GameEventType.GameLangueChange));
        }

        public string LoadText(string _strIndex)
        {
            if (!_strIndex.StartsWith(@"TEXT_") || null == Config)
                return _strIndex;

            CSharpLuaTable textContainer = Config[_strIndex];
            if (null == textContainer || GameLangue.Invalid == Langue)
                return string.Concat("[", _strIndex, "]");

            string ret = textContainer.GetField(Langue.ToString()); 
            if (null == ret)
                return string.Concat("[", _strIndex, "]");
            return ret;
        }   
    }
}

